const { get_modules_of_dir } = require("../utils");
const sequelize = require("./sequelize_ins");
const associate_models = require("./models_association");

module.exports = {
  models: {},
  async register() {
    //收集模型
    const dir = `${__dirname}/modules`;
    const models = await get_modules_of_dir(dir, ".model.js");
    models.forEach((model) => (this.models[model.core.name] = model));

    //关联模型
    const model_cores = {};
    models.forEach((model) => (model_cores[model.core.name] = model.core));
    associate_models(model_cores);

    //同步表
    // await sequelize.sync({ alter: true });
  },
};
